package models

import (
	"database/sql/driver"

	"github.com/goravel/framework/database/orm"
	"github.com/goravel/framework/support/json"
)

type Meta struct {
	Hidden     bool   `json:"hidden"`
	AlwaysShow bool   `json:"alwaysShow"`
	Title      string `json:"title"`
	Icon       string `json:"icon"`
	NoCache    bool   `json:"noCache"`
	Breadcrumb bool   `json:"breadcrumb"`
	Affix      bool   `json:"affix"`
	ActiveMenu bool   `json:"activeMenu"`
	NoTagView  bool   `json:"noTagView"`
	CanTo      bool   `json:"canTo"`
}

func (m *Meta) Value() (driver.Value, error) {

	return json.Marshal(m)
}
func (m *Meta) Scan(value interface{}) error {
	return json.Unmarshal(value.([]byte), m)
}

type Menu struct {
	orm.Model
	ParentId  uint   `gorm:"type:int(11);default:0" json:"parent_id"`
	Type      string `gorm:"type:char(1);default:'M'" json:"type"`
	Redirect  string `gorm:"type:varchar(255);default:''" json:"redirect"`
	Name      string `gorm:"type:varchar(255);default:''" json:"name"`
	Meta      Meta   `gorm:"type:json;" json:"meta"`
	Component string `gorm:"type:varchar(255);default:''" json:"component"`
	Path      string `gorm:"type:varchar(255);default:''" json:"path"`
	Children  []Menu `json:"children" gorm:"-"`
}

func (m *Menu) TableName() string {
	return "go_menu"
}
